<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-8-12
 * Time: 上午11:35
 */
include('/var/www/html/new/d/module/qkxproject/api/des/Curl.class.php');
class  ShenYouHuaXia{

    public function __construct($UUlid=''){

                $this->user  = 'EBUSINESS_PFT';
                $this->pwd = 'JOYTIME@PFT';



    }
    public  function submitOrder($request_array){
        $request_array['UUplaytime'] = date('Ymd',strtotime($request_array['UUplaytime']));
        $request_array['UUendtime'] = date('Ymd',strtotime($request_array['UUendtime']));
        $request_array = array(
            'TICKETUUID' => $request_array['uuid'],
            'ORDERID' => $request_array['pftordernum'],//票付通订单号
            'TICKETORDERID' => $request_array['pftordernum'],//票付通订单号
            'ORDERDATE' => $request_array['UUordertime'],
            'NUMBER' => $request_array['IDcar'],//身份证号
            'COUNT' => $request_array['UUtnum'],//人数
            'PRICE' => $request_array['UUlprice'],
            'AMOUNT'=>$request_array['UUtotalmoney']/100,//总金额
            'QRCODE'=>$request_array['UUcode'], //二维码
            'BEGINDATE' => $request_array['UUplaytime'].'000000',
            'ENDDATE' => $request_array['UUendtime'].'235959',
            'TYPE' => 2 ,
            'SOURCE' => '厦门神游华夏',
            'MOBILE' => $request_array['UUordertel'],
            'NAME' => $request_array['pftordername'],
            'NETWORK' => '票付通',
            'PATH' => $request_array['UUdname'],
        );
//        print_r($request_array);
//         exit;
//        $record = json_encode($request_array,true);
        $method =  'submitOrder';
        $url = 'http://117.29.164.98:8008/et/ebusiness/'.$method.'.do?';
        $cu = new Cu();
        $result = $cu->curl_post($url, $request_array, $this->user, $this->pwd);
        $arr = json_decode($result,true);
        $code = (string)$arr['content']['code'];
        $message = (string)$arr['content']['message'];
//        var_dump($code);
        if($code == 1){
           $this-> logfile(date('Y-m-d H:i:s') . '|' .$request_array['ORDERID']. '|' .''. '|' .$request_array['COUNT'], '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/sub_order_success.txt');
            return 100;
        }else{
            $this-> logfile(date('Y-m-d H:i:s') . '|' . '|' .$code. '|' .$message, '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/syhx_fail_log.txt');
            return 101;
        }
    }
    public  function  returnOrder($order_true){

        $method =  'returnOrder';
        $url = 'http://117.29.164.98:8008/et/ebusiness/'.$method.'.do?';
        $order_true=array('ORDERID'=>$order_true);
        $cu = new Cu();
        $result = $cu->curl_post( $url, $order_true, $this->user, $this->pwd);
        $arr = json_decode($result,true);
        $code = (string)$arr['content']['code'];
        $message = (string)$arr['content']['message'];
        if($code == 1){
            $this-> logfile(date('Y-m-d H:i:s') . '|' .$order_true. '|' .$code. '|' .$message, '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/syhx_log.txt');
            return 100;
        }else{
            $this-> logfile(date('Y-m-d H:i:s') . '|' .$order_true. '|' .$code. '|' .$message, '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/syhx_log.txt');
            return 101;
        }
    }
public function  takeTicket($order){

    $this->method =  'takeTicket';
    $this->url = 'http://117.29.164.98:8008/et/ebusiness/'.$this->method.'.do?';
    $order_true=array('ORDERID'=>$order);
    $cu = new Cu();
    $result = $cu->curl_post( $this->url, $order_true, $this->user, $this->pwd);
    $arr = json_decode($result,true);


    $code = (string)$arr['content']['code'];
    $message = (string)$arr['content']['message'];
    if($code == 1){
        $this-> logfile(date('Y-m-d H:i:s') . '|' . $order_true.'|' .$code. '|' .$message, '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/syhx_log.txt');
        return 100;

    }else{

        $this-> logfile(date('Y-m-d H:i:s') . '|' .$order_true. '|' .$code. '|' .$message, '/var/www/html/new/d/module/qkxproject/api/shenyouhuaxia/syhx_log.txt');
        return 101;
    }
}


    function logfile($txt, $path)
    {
        $fp = fopen($path, "a");
        flock($fp, LOCK_EX);
        fwrite($fp, $txt . "\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }

}